package xyz.thoughtset.viewer.common.envvar.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import xyz.thoughtset.viewer.common.annotation.log.DataOptLog;
import xyz.thoughtset.viewer.common.core.entity.BaseMeta;
import xyz.thoughtset.viewer.common.core.entity.IdMeta;
import xyz.thoughtset.viewer.common.crud.core.annotation.ApiCRUDPower;

import java.util.Objects;


@NoArgsConstructor
@AllArgsConstructor
@Data
@TableName
@DataOptLog
@ApiCRUDPower(insert = false,update = false,list = true)
public class EnvVars extends IdMeta {
    protected String type;
    protected String topic;
    protected String payload;
    protected transient Object pbo;

    public <T> T getPayloadBody(Class<T> tarType) {
        return (T) pbo;
    }

    public EnvVars setBody(Object obj){
        this.pbo = obj;
        this.payload = null;
        return this;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        EnvVars obj = (EnvVars) o;
        return id.equals(obj.id);
    }

}
